package com.example.demo.dataobject;

import com.example.demo.model.Order;
import com.example.demo.model.OrderStatus;

import java.time.LocalDateTime;

/**
 * 订单数据库对象
 */
public class OrderDO {
    private String id;//主键
    private String orderNumber;//订单编号
    private Long userId;//用户Id
    private String productId;//商品Id
    private String productDetailId;//商品详情Id
    private Double totalPrice;//订单总价格
    private String status;//订单状态
    private LocalDateTime gmtCreated;//创建时间
    private LocalDateTime gmtModified;//修改时间

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getOrderNumber() {
        return orderNumber;
    }

    public void setOrderNumber(String orderNumber) {
        this.orderNumber = orderNumber;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public String getProductDetailId() {
        return productDetailId;
    }

    public void setProductDetailId(String productDetailId) {
        this.productDetailId = productDetailId;
    }

    public Double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(Double totalPrice) {
        this.totalPrice = totalPrice;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public LocalDateTime getGmtCreated() {
        return gmtCreated;
    }

    public void setGmtCreated(LocalDateTime gmtCreated) {
        this.gmtCreated = gmtCreated;
    }

    public LocalDateTime getGmtModified() {
        return gmtModified;
    }

    public void setGmtModified(LocalDateTime gmtModified) {
        this.gmtModified = gmtModified;
    }

    /**
     * 数据库对象转换成模型
     * @return Order订单模型
     */
    public Order toModel() {
        Order order = new Order();
        order.setId(id);
        order.setOrderNumber(orderNumber);
        order.setUserId(userId);
        order.setProductId(productId);
        order.setProductDetailId(productDetailId);
        order.setTotalPrice(totalPrice);
        order.setStatus(OrderStatus.valueOf(status));
        order.setGmtCreated(gmtCreated);
        order.setGmtModified(gmtModified);
        return order;
    }
}
